package com.weishi.project.training.controller;

import java.util.List;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.weishi.framework.aspectj.lang.annotation.Log;
import com.weishi.framework.aspectj.lang.enums.BusinessType;
import java.util.Arrays;
import com.weishi.project.training.domain.SchemeDetails;
import com.weishi.project.training.service.ISchemeDetailsService;
import com.weishi.framework.web.controller.BaseController;
import com.weishi.framework.web.domain.AjaxResult;
import com.weishi.common.utils.poi.ExcelUtil;
import com.weishi.framework.web.page.TableDataInfo;

/**
 * 训练方案子表
 */
@RestController
@RequestMapping("/training/schemeDetails")
public class SchemeDetailsController extends BaseController {

    /**
     * 训练方案子表接口
     */
    @Autowired
    private ISchemeDetailsService schemeDetailsService;



    /**
     * 查询训练方案子列表
     */
    @RequestMapping(value = "/list", method = RequestMethod.POST)
    @ResponseBody
    public AjaxResult list(Long id) {
        return AjaxResult.success(schemeDetailsService.list(Wrappers.<SchemeDetails>lambdaQuery().eq(SchemeDetails::getTblSchemeId , id)));
    }


    /**
     * 导出训练方案子列表
     */
    @Log(title = "训练方案子", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SchemeDetails schemeDetails) {
        List<SchemeDetails> list = schemeDetailsService.selectSchemeDetailsList(schemeDetails);
        ExcelUtil<SchemeDetails> util = new ExcelUtil<SchemeDetails>(SchemeDetails.class);
        return util.exportExcel(list, "details");
    }


    /**
     * 获取训练方案子详细信息
     */
    @RequestMapping(value = "/getInfo", method = RequestMethod.POST)
    @ResponseBody
    public AjaxResult getInfo(@RequestBody Long id) {
        return AjaxResult.success(schemeDetailsService.getById(id));
    }


    /**
     * 新增训练方案子
     */
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    @ResponseBody
    public AjaxResult add(@RequestBody SchemeDetails schemeDetails) {
        schemeDetailsService.save(schemeDetails);
        return AjaxResult.success();
    }


    /**
     * 修改训练方案子
     */
    @RequestMapping(value = "/edit", method = RequestMethod.POST)
    @ResponseBody
    public AjaxResult edit(@RequestBody SchemeDetails schemeDetails) {
        schemeDetailsService.updateById(schemeDetails);
        return AjaxResult.success();
    }


    /**
     * 删除训练方案子
     */
    @RequestMapping(value = "/removeById", method = RequestMethod.POST)
    @ResponseBody
    public AjaxResult removeById(Long id) {
        schemeDetailsService.removeById(id);
        return AjaxResult.success();
    }












}